package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/changdu/config"
	"net/http"
	"net/url"
)

type UserListV1ApiService service

type UserListV1GetRequest struct {
	ctx              context.Context
	ApiService       *UserListV1ApiService
	distributorId    *uint64
	mediaSource      *uint
	bookSource       *string
	promotionId      *string
	showNotRecharge  *bool
	pageSize         *uint64
	pageIndex        *uint64
	optimizerAccount *string
	beginTime        *uint
	endTime          *uint
	openId           *string
	externalId       *string
}

type UserListV1GetResponse struct {
	Code    *int64                 `json:"code,omitempty"`
	Message *string                `json:"message,omitempty"`
	Result  []*UserListV1GetResult `json:"data,omitempty"`
	Total   *uint64                `json:"total,omitempty"`
}

type UserListV1GetResult struct {
	EncryptedDeviceId *string   `json:"encrypted_device_id,omitempty"`
	OpenId            *string   `json:"open_id,omitempty"`
	DeviceBrand       *string   `json:"device_brand,omitempty"`
	MediaSource       *string   `json:"media_source,omitempty"`
	BookSource        *string   `json:"book_source,omitempty"`
	RechargeTimes     *uint     `json:"recharge_times,omitempty"`
	RechargeAmount    *uint     `json:"recharge_amount,omitempty"`
	BalanceAmount     *uint     `json:"balance_amount,omitempty"`
	RegisterTime      *string   `json:"register_time,omitempty"`
	PromotionId       *string   `json:"promotion_id,omitempty"`
	PromotionName     *string   `json:"promotion_name,omitempty"`
	BookName          *string   `json:"book_name,omitempty"`
	ClickId           *string   `json:"clickid,omitempty"`
	OaId              *string   `json:"oaid,omitempty"`
	CaId              *string   `json:"caid,omitempty"`
	AdId              *uint     `json:"adid,omitempty"`
	CreativeId        *uint     `json:"creativeid,omitempty"`
	CreativeType      *uint     `json:"creativetype,omitempty"`
	Ip                *string   `json:"ip,omitempty"`
	UserAgent         *string   `json:"user_agent,omitempty"`
	Timestamp         *uint     `json:"timestamp,omitempty"`
	OptimizerAccount  *string   `json:"optimizer_account,omitempty"`
	ExternalId        *string   `json:"external_id,omitempty"`
	ProjectId         *string   `json:"project_id,omitempty"`
	AdIdV2            *string   `json:"ad_id_v2,omitempty"`
	Mid               []*string `json:"mid,omitempty"`
	ClueToken         *string   `json:"clue_token,omitempty"`
}

func (r *UserListV1GetRequest) DistributorId(distributorId uint64) *UserListV1GetRequest {
	r.distributorId = &distributorId
	return r
}
func (r *UserListV1GetRequest) MediaSource(mediaSource uint) *UserListV1GetRequest {
	r.mediaSource = &mediaSource
	return r
}
func (r *UserListV1GetRequest) BookSource(bookSource string) *UserListV1GetRequest {
	r.bookSource = &bookSource
	return r
}

func (r *UserListV1GetRequest) PromotionId(promotionId string) *UserListV1GetRequest {
	r.promotionId = &promotionId
	return r
}

func (r *UserListV1GetRequest) ShowNotRecharge(showNotRecharge bool) *UserListV1GetRequest {
	r.showNotRecharge = &showNotRecharge
	return r
}

func (r *UserListV1GetRequest) PageSize(pageSize uint64) *UserListV1GetRequest {
	r.pageSize = &pageSize
	return r
}

func (r *UserListV1GetRequest) PageIndex(pageIndex uint64) *UserListV1GetRequest {
	r.pageIndex = &pageIndex
	return r
}

func (r *UserListV1GetRequest) OptimizerAccount(optimizerAccount string) *UserListV1GetRequest {
	r.optimizerAccount = &optimizerAccount
	return r
}

func (r *UserListV1GetRequest) BeginTime(beginTime uint) *UserListV1GetRequest {
	r.beginTime = &beginTime
	return r
}

func (r *UserListV1GetRequest) EndTime(endTime uint) *UserListV1GetRequest {
	r.endTime = &endTime
	return r
}

func (r *UserListV1GetRequest) OpenId(openId string) *UserListV1GetRequest {
	r.openId = &openId
	return r
}

func (r *UserListV1GetRequest) ExternalId(externalId string) *UserListV1GetRequest {
	r.externalId = &externalId
	return r
}

func (r *UserListV1GetRequest) Execute() (*UserListV1GetResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *UserListV1GetRequest) SecretKey(SecretKey string) *UserListV1GetRequest {
	r.ctx = context.WithValue(r.ctx, config.SecretKey, SecretKey)
	return r
}

func (r *UserListV1GetRequest) WithLog(enable bool) *UserListV1GetRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *UserListV1ApiService) Get(ctx context.Context) *UserListV1GetRequest {
	return &UserListV1GetRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *UserListV1ApiService) getExecute(r *UserListV1GetRequest) (*UserListV1GetResponse, *http.Response, error) {
	var (
		localVarPath         = a.client.Cfg.GetBasePath() + "/novelsale/openapi/user/list/v1/"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *UserListV1GetResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasReqParam(r.distributorId, "DistributorId"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	if ok, GenericOpenAPIError := hasReqParam(r.pageIndex, "PageIndex"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	if ok, GenericOpenAPIError := hasReqParam(r.pageSize, "PageSize"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	localVarQueryParams.Add("distributor_id", toString(r.distributorId))
	localVarQueryParams.Add("page_index", toString(r.pageIndex))
	localVarQueryParams.Add("page_size", toString(r.pageSize))

	if r.mediaSource != nil {
		localVarQueryParams.Add("media_source", toString(r.mediaSource))
	}
	if r.bookSource != nil {
		localVarQueryParams.Add("book_source", toString(r.bookSource))
	}
	if r.promotionId != nil {
		localVarQueryParams.Add("promotion_id", toString(r.promotionId))
	}
	if r.showNotRecharge != nil {
		localVarQueryParams.Add("show_not_recharge", toString(r.showNotRecharge))
	}

	if r.optimizerAccount != nil {
		localVarQueryParams.Add("optimizer_account", toString(r.optimizerAccount))
	}
	if r.beginTime != nil {
		localVarQueryParams.Add("begin_time", toString(r.beginTime))
	}
	if r.endTime != nil {
		localVarQueryParams.Add("end_time", toString(r.endTime))
	}
	if r.openId != nil {
		localVarQueryParams.Add("open_id", toString(r.openId))
	}
	if r.externalId != nil {
		localVarQueryParams.Add("external_id", toString(r.externalId))
	}
	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
